CFLAGS = -g -std=c99 -Wall
CC = @gcc

# executable name
NAME = game

# sources
SRCS = 	main.c 			\
		terrain.c 		\
		logger.c 		\
		menu.c			\
		display.c 		\
		worlds.c 		\
		parser.c 		\
		archiver.c 		\
		dynamic_list.c 	\
		cli.c			

# objects
OBJDIR = obj
OBJS := $(SRCS:.c=.o)
OBJS := $(addprefix $(OBJDIR)/, $(OBJS))

ifdef OS
	NAME := $(addsuffix .exe,$(NAME))
	LIBS = -lalleg
else
	LIBS = -L/usr/lib -lm -llua5.1 -lSDL -lSDL_net -lpthread -lXxf86vm -lXcursor -lXpm -lXext -lX11 -ldl -lldpng -lpng -lz -lzzip -lxml2 -lalleg
endif

# need output dir and the executable
all : $(OBJDIR) $(NAME)

# output dir
$(OBJDIR):
	@echo "Creating directory '"$(OBJDIR)"'" 
	@mkdir $(OBJDIR)
	
	
# link the executable
$(NAME): $(OBJS)	# depends on object files
	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
	@echo "PROJECT SUCCESSFULY COMPILED!\n"

$(OBJDIR)/%.o : %.c include/cli.h include/global.h include/terrain.h \
					include/logger.h include/menu.h include/parser.h \
					include/dynamic_list.h
# @echo "[GCC] "$<
	$(CC) $(CFLAGS) -c $< -o $@
	
clean:
	@rm -f -r $(OBJDIR)
	@rm -f $(NAME)
	@echo "REMOVED '"$(OBJDIR)"' AND '"$(NAME)"'\n"
	
